package cn._2dland.http.method.multiparts;

import java.io.ByteArrayOutputStream;

/**
 * 字符串数据块
 * 
 * @author deadblue
 */
public class StringPart extends Part {
	/**参数值 */
	private String value = null;

	public StringPart(String name, String value) {
		super(name);
		this.value = value;
	}

	@Override
	public byte[] getBytes() {
		ByteArrayOutputStream ba = new ByteArrayOutputStream();
		try {
			StringBuffer buf = new StringBuffer();
			buf.append("Content-Disposition: form-data; name=\"").append(name).append("\"")
				.append(CRLF).append(CRLF).append(value).append(CRLF);
			// 写入输出流
			ba.write(buf.toString().getBytes(charset));
		}
		catch (Exception e) { e.printStackTrace(); }
		return ba.toByteArray();
	}
}